package com.guang.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author lg
 * @Description
 * @date 2022/10/25 10:03
 */
public class ThreadCallableTest implements Callable<String> {

    @Override
    public String call() throws Exception {
        System.out.println(String.format("当前的线程名称是：%s",Thread.currentThread().getName()));
        return "success";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadCallableTest thread = new ThreadCallableTest();
        FutureTask<String> futureTask = new FutureTask<>(thread);
        Thread t1 = new Thread(futureTask, "t1");
        t1.start();
        System.out.println("-------------------------------------------");
        System.out.println(String.format("当前的线程名称是：%s",Thread.currentThread().getName()));
        System.out.println(futureTask.get());
    }
}
